package com.jisf.driver.auth;

import com.jisf.driver.response.Result;
import com.jisf.driver.response.ResultCode;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Classname MyAuthenticationEntryPoint
 * @Description TODO 匿名用户访问无权限资源时异常
 * @Date 2022/4/4 21:57
 * @Created by jisf：【429627912@qq.com】
 */
@Component("myAuthenticationEntryPoint")
public class MyAuthenticationEntryPoint extends JsonAuthentication implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e) throws IOException, ServletException {
        Result result = Result.error(ResultCode.USER_NOT_LOGIN);
        this.WriteJSON(request, response, result);
    }
}
